/**
 * 产品类型编辑
 */
layui.use(['layer', 'form', 'admin', 'ax', 'inputTags'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;
    var inputTags = layui.inputTags;



    //初始化角色的详情数据
    var ajax = new $ax(Feng.ctxPath + "/productType/detail/" + Feng.getUrlParam("id"));
    var result = ajax.start();
    var labelStr = result.data.label;
    result.data.label = "";
    form.val('productTypeForm',result.data);


    var labelAttr = [];
    if(labelStr != null && labelStr.length>0){
        labelAttr = labelStr.split(",");
        //去空
        labelAttr = labelAttr.filter(function (s) {
            return s && s.trim();
        });
    }
    inputTags.render({
        elem: '#label', //定义输入框input对象
        content: labelAttr, //默认标签
        aldaBtn: false, //是否开启获取所有数据的按钮
        done: function(value) { //回车后的回调
            labelStr += value+","
            console.log("刚刚输入标签===="+value);
        }
    });

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        data.field.label = labelStr;
        var ajax = new $ax(Feng.ctxPath + "/productType/update", function (data) {
            Feng.success("修改成功!");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("修改失败!" + data.responseJSON.message + "!");
        });
        ajax.set(data.field);
        ajax.start();

        //添加 return false 可成功跳转页面
        return false;
    });
});